<?php

namespace yiike\finance\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use yiike\finance\models\TokerWithdraw;

/**
* TokerWithdrawSearch represents the model behind the search form about `yiike\finance\models\TokerWithdraw`.
*/
class TokerWithdrawSearch extends TokerWithdraw
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'weid', 'uid', 'toker_id', 'type', 'status', 'is_pay', 'created_at', 'check_at', 'check_by', 'pay_at', 'pay_by'], 'integer'],
            [['money', 'unlock_rate', 'unlock_money', 'real_pay'], 'number'],
            [['pay_sn', 'wx_openid', 'alipay', 'bank', 'payee', 'bank_account', 'memo'], 'safe'],
];
}

/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}

/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = TokerWithdraw::find();

$dataProvider = new ActiveDataProvider([
'query' => $query,
]);

if (! isset($params['sort'])) {
    $params['sort'] = '-id';
}

$this->load($params);

if (!$this->validate()) {
// uncomment the following line if you do not want to any records when validation fails
// $query->where('0=1');
return $dataProvider;
}

$query->andFilterWhere([
            'id' => $this->id,
            'weid' => $this->weid,
            'uid' => $this->uid,
            'toker_id' => $this->toker_id,
            'type' => $this->type,
            'money' => $this->money,
            'unlock_rate' => $this->unlock_rate,
            'unlock_money' => $this->unlock_money,
            'real_pay' => $this->real_pay,
            'status' => $this->status,
            'is_pay' => $this->is_pay,
            'created_at' => $this->created_at,
            'check_at' => $this->check_at,
            'check_by' => $this->check_by,
            'pay_at' => $this->pay_at,
            'pay_by' => $this->pay_by,
        ]);

        $query->andFilterWhere(['like', 'pay_sn', $this->pay_sn])
            ->andFilterWhere(['like', 'wx_openid', $this->wx_openid])
            ->andFilterWhere(['like', 'alipay', $this->alipay])
            ->andFilterWhere(['like', 'bank', $this->bank])
            ->andFilterWhere(['like', 'payee', $this->payee])
            ->andFilterWhere(['like', 'bank_account', $this->bank_account])
            ->andFilterWhere(['like', 'memo', $this->memo]);

return $dataProvider;
}
}